<script setup>
import {defineProps, defineEmits} from 'vue';

// 通过 defineProps 接收来自父组件的 list 数据
const props = defineProps({
  list: {
    type: Array,
    required: true
  }
});
const emit = defineEmits(['del']);

const handleDel = (id) => {
  emit('del', id);
};
</script>

<template>
  <!-- 列表区域 -->
  <section class="main">
    <ul class="todo-list">
      <li class="todo" v-for="(item, index) in props.list" :key="index">
        <div class="view">
          <span class="index">{{ index + 1 }}.</span> <label>{{ item.name }}</label>
          <button class="destroy" @click="handleDel(item.id)"></button>
        </div>
      </li>
    </ul>
  </section>
</template>

<style scoped>

</style>